Fix UFuncTypeError for integer input coordinates (#300)#312
Open
gaoflow wants to merge 1 commit into
Open
Conversation
…k#300) _adjust_for_anisotropy subtracts the (float) center from the input coordinates in place via 'X -= center'. When the coordinates are given as an integer array (e.g. OrdinaryKriging(x, y, ...) with integer x/y, or integer query points in execute()), NumPy refuses the in-place subtraction under the 'same_kind' casting rule and raises: numpy._core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('int64') ... Cast X to float64 at the start of the function (the docstring already documents X as a float array). This fixes ordinary and universal kriging in 2D and 3D, since they all route coordinate handling through this function. Adds a regression test. Closes GeoStat-Framework#300
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #300
Problem
core._adjust_for_anisotropysubtracts the (float) center from the input coordinates in place:When the coordinates are integers — e.g.
OrdinaryKriging(x, y, z)with integerx/y, or integer query points passed toexecute("points", ...)— NumPy (≥ 2) refuses the in-place subtraction under thesame_kindcasting rule:Reproduction (current
main, NumPy 2.4)Fix
Cast
Xtofloat64at the start of_adjust_for_anisotropy. The docstring already documentsXas a float array, so this simply enforces that contract. All Ordinary/Universal Kriging classes (2D and 3D) route their coordinate handling through this single function, so the one-line fix covers every variant.Verification
test_core_adjust_for_anisotropy_integer_coords(unit-level + an end-to-endOrdinaryKrigingrun); it fails onmainwith theUFuncTypeErrorand passes with this change.tests/suite: 54 passed, 2 skipped (no new failures).black/isortclean.